-- attack_status
-- created by zhuangsl
-- 攻击附加通用状态

return {
    apply = function(prop, baseValue)
        return prop[2];
    end,

    -- 攻击触发
    trigger = function(who, prop, arg)
        local target = arg;

        -- 概率触发
        local rand = DungeonM.getRandSeed("attack_status") % 1000;
        if (rand > prop[3]) then
            return;
        end

        -- 持续时间
        local round = prop[4];
        if round > 0 then
            round = CombatM.getRound() + round + 1;
        end

        -- TODO: 状态参数
        local condition = {
            ["end_round"] = round,
        };

        local propId, v;
        if prop[2] == "spin" then
            condition["id"] = PropM.getPropId(prop[2]);
        elseif prop[2] == "bleed" then
            propId = PropM.getPropId(prop[2]);
            v = math.modf(ME.user:queryAttrib("attack") / 2);
            condition["prop"] = { propId, 1, v, round };
        elseif prop[2] == "curse" then
            propId = PropM.getPropId(prop[2]);
            condition["prop"] = { propId, 1, 500, round };
        end

        -- 附加状态
        CombatStatusM.applyStatus(target, prop[2], condition);
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        if prop[2] == "curse" then
            desc = row.append_desc;
        end

        local status = prop[2];
        local statsId = CombatStatusM.getStatusId(status);
        local statusName = CombatStatusM.query(statsId, "name");
        local v = math.modf(prop[3] / 10);

        desc = string.gsub(desc, "{0}", statusName);
        desc = string.gsub(desc, "{1}", v);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};
